<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 创建对象发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <button>点击获取段子</button>
    <button>本地server</button>

    <script>
        //通过 axios.create 方法创建两个对象
        let localAxios = axios.create({
            baseURL: 'http://127.0.0.1:8090'
        });

        let remoteAxios = axios.create({
            baseURL : 'https://api.xiaohigh.com'  // https://api.xiaohigh.com/duanzi
        });

        //获取按钮
        let btns = document.querySelectorAll('button');

        btns[0].onclick =async function(){
            //当做函数使用
            let res = await remoteAxios('/duanzi');
            console.log(res);
        }

        btns[1].onclick = async function(){
            //当做对象使用
            let res = await localAxios.get('/server');
            console.log(res);
        }

    </script>
</body>
</html>